select 
	[Northwind_mart].[dbo].time_dim.time_key,
	[Northwind_mart].[dbo].customer_dim.customer_key,
	[Northwind_mart].[dbo].shipper_dim.shipper_key,
	[Northwind_mart].[dbo].product_dim.product_key,
	[Northwind_mart].[dbo].employee_dim.employee_key,
	northwind.dbo.orders.requireddate,
	orders.freight * [order details].quantity / (
		select sum(quantity)
		from [order details] od 
		where od.orderid=orders.orderid
		) as LineItemFreight,
	[order details].unitprice * [order details].quantity as LineItemTotal, 
	[order details].quantity as LineItemQuantity,
	[order details].discount * [order details].unitprice * [order details].qunatity as LineItemDiscount
from Orders, [order details]
where orders.orderid=[order details].orderid
and [order details].productid=[northwind_mart].[dbo].product_dim.product_id
and orders.customerid=northwind_mart.dbo.customer_dim.customer_id
and orders.shippeddate=northwind_mart.dbo.time_dim.the_date
and orders.shipvia=northwind_mart.dbo.shipper_dim.shipper_id
and orders.employee_id=northwindmart.dbo.employee_dim.employee_id
and orders.shippeddate is not null
******************************************************************




SELECT
     Northwind_Mart.dbo.Time_Dim.Time_Key,
     Northwind_Mart.dbo.Customer_Dim.Customer_Key,
     Northwind_Mart.dbo.Shipper_Dim.Shipper_Key,
     Northwind_Mart.dbo.Product_Dim.Product_Key,
     Northwind_Mart.dbo.Employee_Dim.Employee_Key,      
     Northwind.dbo.Orders.RequiredDate,      
     Orders.Freight * [Order Details].Quantity /          
          (SELECT SUM(Quantity)
           FROM [Order Details] od
           WHERE od.OrderID = Orders.OrderID) AS LineItemFreight,
     [Order Details].UnitPrice * [Order Details].Quantity AS LineItemTotal,
     [Order Details].Quantity AS LineItemQuantity,
     [Order Details].Discount * [Order Details].UnitPrice *
          [Order Details].Quantity AS LineItemDiscount 
FROM Orders  

INNER JOIN [Order Details]
      ON Orders.OrderID = [Order Details].OrderID  
INNER JOIN Northwind_Mart.dbo.Product_Dim
      ON [Order Details].ProductID = 
      Northwind_Mart.dbo.Product_Dim.Product_ID  
INNER JOIN Northwind_Mart.dbo.Customer_Dim
      ON Orders.CustomerID = 
      Northwind_Mart.dbo.Customer_Dim.Customer_ID  
INNER JOIN Northwind_Mart.dbo.Time_Dim
      ON Orders.ShippedDate = Northwind_Mart.dbo.Time_Dim.The_Date  
INNER JOIN Northwind_Mart.dbo.Shipper_Dim
      ON Orders.ShipVia = Northwind_Mart.dbo.Shipper_Dim.Shipper_ID  
INNER JOIN Northwind_Mart.dbo.Employee_Dim
      ON Orders.EmployeeID = 
      Northwind_Mart.dbo.Employee_Dim.Employee_ID  
WHERE (Orders.ShippedDate IS NOT NULL)
